<?php
/**
 * 支持布局的视图,需要开启插件机制,以便通过插件设置布局所需要的全局数据
 */
uses ( 'mvc.view.HtmlView' );
class LayoutView extends HtmlView {
	/**
	 * 绘制
	 * @param array $data
	 * @param Response $response
	 * @param string $tpl
	 * @return string
	 */
	public function render($data, $response, $tpl = '') {
		
		$LAYOUT_CONTENT = parent::render ( $data, $response, $tpl );
		
		$__layout = $response->getLayout ();
		$__layout_data = apply_filter ( 'before_render_layout', array ('LAYOUT_TITLE' => $response->title, 'LAYOUT_KEYWORDS' => $response->keywords, 'LAYOUT_DESC' => $response->desc ) );
		$__layout_data = apply_filter ( 'before_render_layout_' . $__layout, $__layout_data );
		
		$__layout_file = LAYOUT . $__layout . HtmlView::EXT;
		if (is_file ( $__layout_file )) {
			extract ( $__layout_data );
			@ob_start ();
			include $__layout_file;
			$content = @ob_get_contents ();
			@ob_end_clean ();
			return $content;
		} else {
			$response->error ( 'The layout ' . $__layout . ' is not found', 404 );
		}
	}
}